<template>
  <div class="app-container">
    <el-dialog title="信息" :visible.sync="openContractVersion" width="800px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
      <el-form size="small" :inline="true" label-width="120px" :label-position="labelPosition">
        <el-form-item label="合同编号" prop="csbh">
            <el-input
            v-model="csbh"
            :disabled="true"
            />
        </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="contractVersionDetail"
    >
      <af-table-column fixed="left" label="操作" width="100" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
            <el-button
                v-show="scope.row.fq == '正在生效'"
                size="mini"
                type="text"
                @click="handleDiscardVersion(scope.row)"
                v-hasPermi="['zhcloud:sfbz:list']"
            >废弃版次</el-button>
        </template>
      </af-table-column>
      <af-table-column prop="cx" label="版次" width="100" fixed="left"></af-table-column>
      <af-table-column prop="sdate" label="开始日期"></af-table-column>
      <af-table-column prop="edate" label="结束日期"></af-table-column>
      <af-table-column prop="fq" label="合同状态"></af-table-column>
    </el-table>
     <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
    </el-dialog>
  </div> 
</template>

<script>
import { getContractVersionDetail,contractVersionDiscard } from "@/api/storage/contractFeeStandard";

export default {
  name: "ContractVersion",
  data() {
    return {
      //对齐
      labelPosition: "right",
      //加载列表
      loading:true,
      //弹窗状态
      openContractVersion:false,
      csbh:"",
      // 查询参数
      queryParams: {
        csuid: "",
      },
      //废弃参数
      delQureyParams: {
        fqid:""
      },
      // 合同版次详情
      contractVersionDetail: [],
      //页数
      pageSize: 999,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  methods: {
    /** 查询合同版次详情 */
    getList() {
      this.loading = true
      getContractVersionDetail(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.contractVersionDetail = response.data;
        this.loading = false
      });
    },
    //废弃版次
    handleDiscardVersion(data) {
        this.$modal.confirm("是否废弃此版次?").then(() => {
            this.$modal.loading("数据正在处理中，请稍等...")
            this.delQureyParams.fqid = data.id
            contractVersionDiscard(this.delQureyParams).then(response => {
                this.$modal.closeLoading()
                this.$modal.msgSuccess('废弃成功！')
                this.getList()
            }).catch(()=> {
            this.$modal.closeLoading()
        })
      }).catch(() => {})
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
    /**关闭弹窗 */
    beforeClose(done) {
      this.close()
      done()
    },
    /**关闭窗口 */
    close() {
      this.changeContractVersion()
      this.reset()
    },
    /**改变窗口状态 */
    changeContractVersion() {
      this.openContractVersion = !this.openContractVersion;
    },

    /**打开弹窗 */
    open(data) {
      this.changeContractVersion()
      this.queryParams.csuid = data.uid
      this.csbh = data.csbh
      this.getList()
    },
  }
};
</script>
